package co.wizardattack.activities;

import java.io.IOException;

import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.WakeLockOptions;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import protocol.Print;

import co.wizardattack.model.Game;

import android.os.Bundle;
import android.widget.Toast;

public class BattleActivity extends SimpleBaseGameActivity {

	/**
	 * Constantes
	 */
	public static final String BATTLE_MODE = "BATTLE_MODE";
	public static final String RUNNING_MODE = "RUNNING_MODE";
	public static final String ATTACKING_MODE = "ATTACKING_MODE";
	/**
	 * Atributos
	 */
	private Game game;
	private static int contador;
	
	/**
	 * Constructor
	 */
	public BattleActivity() {
		super();
		Print.print("wizardgame", "creacion de la clase BattleActivity");
	}
	
	/**
	 * Metodos
	 */	
	@Override
	protected void onCreate(final Bundle pSavedInstanceState) {
		// Game mode
		boolean gameMode = true;
		Bundle bundle = getIntent().getExtras();
		String message = bundle.getString(BATTLE_MODE);
		Toast.makeText(this, message, 0).show();
		if(message == null)
			finish();
		else if(message.equals(RUNNING_MODE))
			gameMode = true;
		else if(message.equals(ATTACKING_MODE))
			gameMode = false;
		else
			finish();
		
		Print.print("wizardgame", "contador " + (contador++) + " -> " + (gameMode ? RUNNING_MODE : ATTACKING_MODE));
		super.onCreate(pSavedInstanceState);
	}

	@Override
	public EngineOptions onCreateEngineOptions() {
		this.game = new Game();
		EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), game.createCamera());
		engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
		engineOptions.getAudioOptions().setNeedsSound(true);
		engineOptions.getAudioOptions().setNeedsMusic(true);
		return engineOptions;
	}

	@Override
	protected void onCreateResources() throws IOException {
		this.game.onCreateResources(getTextureManager(), getFontManager(), getAssets(), getEngine(), this);
	}

	@Override
	protected Scene onCreateScene() {
		return game.onCreateScene(getVertexBufferObjectManager());
	}

}
